/*
 +-----------------------------------------------------------------------------------------------+
 | Project : UKAPI
 +-----------------------------------------------------------------------------------------------+
 | Project Description : Universal & Kernel API
 +-----------------------------------------------------------------------------------------------+
 | File Description :
 |   Chained List
 |                                                 
 +-----------------------------------------------------------------------------------------------+
 | Licence : MIT Licence
 +-----------------------------------------------------------------------------------------------+
 | Copyright (c) 2006 Olivier Vanhoucke
 | 
 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 | and associated documentation files (the "Software"), to deal in the Software without 
 | restriction, including without limitation the rights to use, copy, modify, merge, publish, 
 | distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 
 | Software is furnished to do so, subject to the following conditions:
 | 
 | The above copyright notice and this permission notice shall be included in all copies or 
 | substantial portions of the Software.
 | 
 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 | BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 +-----------------------------------------------------------------------------------------------+
*/

/**
 * Inclusions standards
 */
#include <ukapi.h>

/**
 * Inclusions locales
 */
#include <list.h>

/**
 * @fn		result_t list_copy( plist_t source, plist_t destination )
 * @brief	Copy a list in another
 * @param	plist_t list : pointer to the source list
 * @param	plist_tlist : pointer to the destination list
 * @return	Result Code
 * @retval	result_ok_e 
 * @retval	result_fail_e
 * @retval	result_invalidargument_e
 */
result_t list_copy( plist_t source, plist_t destination )
{
	register ulong_t	i		= 0;
	plist_node_t		le		= null;

	if (	( source == null ) 
		||	( destination == null )
/*		||	( list_size( source ) != 0 ) */
		)
	{
		return result_invalidargument_e;
	}

	for ( le = list_head( source ); le != null; le = list_next( le ), i++)
	{
		if ( list_insert_next( destination, list_tail( destination ), list_data( le ) ) != 0 )
		{
			return result_fail_e;
		}
	}

	return result_ok_e;
}
